package com.way.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.way.api.mall.RemoteOrderService;
import com.way.domain.mall.Order;
import com.way.domain.system.SysUser;
import com.way.mapper.SysUserMapper;
import com.way.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SysUserService implements ISysUserService {

    @Autowired
    private RemoteOrderService remoteOrderService;

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser getUser(String loginName) {
        return sysUserMapper.getUser(loginName);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @LcnTransaction
    public void saveUser(SysUser user) {
        Order order = new Order();
        order.setReceiveAddress("万盛");
        order.setBusinessInfo("石芫");
        order.setReceiveUserId("999");
        remoteOrderService.createOrder(order);
        sysUserMapper.insert(user);
    }

    @Override
    public List<SysUser> getUserList() {
        return sysUserMapper.selectList(new QueryWrapper<>());
    }
}
